import numpy as np


class TP:

    def __init__(self, env):
        self.env = env

    def run(self):
        # return self.nearest(1)
        return [1, 5, 0, 6, 2, 4, 3]

    def hotspot(self):
        part_ues_num = [len(part) for part in self.env.parts_ues]
        return np.argsort(-np.array(part_ues_num))

    def nearest(self, start_idx=0):
        unsort = list(range(self.env.G))
        unsort.remove(start_idx)
        path = np.zeros(self.env.G, dtype=int)
        path[0] = start_idx
        for i in range(1, self.env.G):
            nearest_idx = path[i - 1]
            nearest_distance = self.env.config.area
            for unsort_idx in unsort:
                distance = np.linalg.norm(self.env.meta_parts[path[i - 1]] - self.env.meta_parts[unsort_idx])
                if distance < nearest_distance:
                    nearest_idx = unsort_idx
                    nearest_distance = distance
            path[i] = nearest_idx
            unsort.remove(nearest_idx)
        return path
